package com.liyuan.help_e.component.crawler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import us.codecraft.webmagic.Spider;

@Configuration
@EnableScheduling
public class CrawlingNews {
    @Autowired
    DbPipeline dbPipeline;
    @Autowired
    GdufsSpider gdufsSpider;
    @Scheduled(cron="40 17 21 * * *")
    public void crawl(){
        crawlGdufs();
    }
    private void crawlGdufs() {
        Spider spider=Spider.create(gdufsSpider);
        spider.addUrl("https://www.gdufs.edu.cn/gwxw.htm")
                .addPipeline(dbPipeline)
                .thread(5)
                .setExitWhenComplete(true);
        spider.start();
    }
}
